package javaClassExercise.set;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by lomo on 2017/3/14.
 */
public class MapTest {

    public static void main(String[] args) {

		/* 初始化map */
        Map<String, Integer> map = new HashMap<String, Integer>();
        System.out.println("初始化后得到的Map相关信息：");
        System.out.println("HashMap的初始值:" + map.size());
        System.out.println("HashMap是否为空:" + (map.isEmpty() ? "是" : "否"));
        Map<Integer, Double> map2 = new HashMap<>();
        map2.put(1, 1.5);
        map2.put(2, 5.5);
        System.out.println("map2:" + map2.size());
        String a = "1.5"; int b = 1;
        System.out.println(map2.hashCode());
        //每次向map类的集合里put数据后，hashCode就会变化; 若没有数据，则hashCode为0


		/* 想map中添加元素 */
        map.put("erqing", 1);
        map.put("niuniu", 2);
        map.put("egg", 3);
        System.out.println(map.size());

        System.out.println("HashMap是否为空:" + (map.isEmpty() ? "是" : "否"));

		/* 遍历HashMap中的元素 */
        Set<String> set = map.keySet();
        for (String s : set) {
            System.out.println(s + " " + map.get(s) + " " + "hashcode:"
                    + s.hashCode());
        }

		/*检测是否含有某个Key*/
        System.out.println(map.containsKey("egg"));

		/*检测是否含有某个Value*/
        System.out.println(map.containsValue(0));

		/*打印hashCode*/
        System.out.println(map.hashCode());
    }
}
